package com.steak.concurrent.Future;

import java.util.concurrent.*;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/2617:09
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();

        Future<String> task1 = executorService.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("start task1");
                Thread.sleep(2000);
                return "task1";
            }
        });

        Future<String> task2 = executorService.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("start task2");
                return "task2";
            }
        });

        System.out.println(task1.get());
        System.out.println(task2.get());
        executorService.shutdownNow();
    }
}
